package yl.hs.bmipfull.controllers.report;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.report.IRawMaterialStatisticService;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.WebResult;

/**
 * 作用:   <br/>
 * 创建时间: 2022-02-23 08:38 <br/>
 * 采购统计控制层
 *
 * @author 吴高丰
 */
@Api(value = "采购统计web接口", tags = "报表中心-采购统计web接口")
@RestController
@RequestMapping(value = "/api/rawmaterialstatistic")
public class RawMaterialStatisticController extends ControllerBase {
    @Autowired
    IRawMaterialStatisticService rawMaterialStatisticService;
    @RequestMapping(value = {"/receipt","/receipt/{productCateSn}"},method = RequestMethod.POST)
    @ApiOperation(value = "查询原材入库分析信息接口",notes = "查询原材入库分析信息接口")
    public WebResult queryReceipt(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery, @ApiParam(value = "产品编号") @PathVariable(required = false) String productCateSn){
        try {
            var rsult = rawMaterialStatisticService.queryReceipt(pageQuery,productCateSn);
            return success("查询成功",rsult);
        }catch (Exception ee){
            return error(ee);
        }
    }

    @RequestMapping(value = {"/supplierAnalysis","/supplierAnalysis/{productCateSn}"},method = RequestMethod.POST)
    @ApiOperation(value = "查询原材入库分析信息接口",notes = "查询原材入库分析信息接口")
    public WebResult querySupplierAnalysis(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery, @ApiParam(value = "产品编号") @PathVariable(required = false) String productCateSn){
        try {
            var rsult = rawMaterialStatisticService.querySupplierAnalysis(pageQuery,productCateSn);
            return success("查询成功",rsult);
        }catch (Exception ee){
            return error(ee);
        }
    }

    @RequestMapping(value = {"/purchase/{productCateSn}"},method = RequestMethod.POST)
    @ApiOperation(value = "查询原材购进汇总",notes = "查询原材购进汇总")
    public WebResult queryRawPurchaseStatistic(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery, @ApiParam(value = "产品编号") @PathVariable String productCateSn){
        try {
            var result = rawMaterialStatisticService.queryRawPurchaseStatistic(pageQuery,productCateSn);
            return success("查询成功",result);
        }catch (Exception ee){
            return error(ee);
        }
    }

    @ApiOperation(value = "原材月报",notes = "查询原材入库、消耗、库存月报")
    @GetMapping( {"/monthReport/{year}/{month}","/monthReport/{year}/{month}/{unit}"})
    public WebResult queryRawMaterialMonthData(@PathVariable int year,@PathVariable int month,@ApiParam(allowEmptyValue = true) @PathVariable(required = false) String unit){
        try{
            var result = rawMaterialStatisticService.queryRawMaterialMonthData(year,month,unit);
            return success("ok",result);
        }
        catch (Exception ee){
            return error(ee);
        }
    }
}
